﻿//open window for selection
function PopupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2) - 50;
    targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    targetWin.focus();
    return;
}
function RedirectUrl(param, title,groupid) {
    var pageurl = "../administrator/default.aspx?mod=" + param + "&groupid=" + groupid + "";
    document.location.href = pageurl;
}
function RedirectUrlComment(param, title,productid) {
    var pageurl = "../administrator/default.aspx?mod=" + param + "&pid=" + productid + "";
    document.location.href = pageurl;
}
function AddUserToGroup(param, groupid, title, width, height) {
    var pageurl = "../administrator/addnewitem.aspx?add=" + param + "&groupid="+groupid+"";
    //SelectWin = window.open("../Administrator/AddNewItem.aspx?add="+url+"", target = "_blank", "left="+left+",top="+top+",width="+width+",height="+height+",toolbar=no,status=no,menubar=no,resizable=no,scrollbars=yes");
    PopupCenter(pageurl, title, width, height);
}
function AddNewItem(param, title, width, height) 
{
    var pageurl = "../administrator/addnewitem.aspx?add=" + param + "";
    //SelectWin = window.open("../Administrator/AddNewItem.aspx?add="+url+"", target = "_blank", "left="+left+",top="+top+",width="+width+",height="+height+",toolbar=no,status=no,menubar=no,resizable=no,scrollbars=yes");
    PopupCenter(pageurl, title, width, height);
}
function EditItem(param, title, itemid, width, height) {
    var pageurl = "../administrator/edititem.aspx?edit=" + param + "&itemid=" + itemid + "";
    PopupCenter(pageurl, title, width, height);
}
function ViewItem(param, title, itemid, width, height) {
    var pageurl = "../administrator/viewitem.aspx?view=" + param + "&itemid=" + itemid + "";
    PopupCenter(pageurl, title, width, height);
} 
function DeleteItemFromGroupUser(groupid, username, itemtitle) {
    if (confirm("Bạn muốn xóa user: " + itemtitle + " ra khỏi nhóm")) {
        RetValue = BLL.CmsBLL.DeleteItemFromTableGroupUser(groupid, username).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        window.location.reload();
        return;
    }
}

function DeleteItem(tablename, keyfield, parentfield, itemid, itemtitle, datatype) {  
    if (confirm("Bạn muốn xóa bản ghi này?")) {       
        RetValue = BLL.CmsBLL.DeleteItemFromTableByID(tablename, keyfield, parentfield, itemid, datatype).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        else {
            alert("Xoá bản ghi thành công!")
            window.location.reload();
            return;
        }
    }
}

function DeleteCustomerItem(itemid) {
    if (confirm("Are you sure?")) {
        RetValue = BLL.Customer_BLL.Customer_DeleteItem(itemid).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        else {
            alert("Success!")
            window.location.reload();
            return;
        }
    }
}

function DeleteOrderItem(itemid) {
    if (confirm("Are you sure?")) {
        RetValue = BLL.CmsBLL.CartOrder_DeleteItem(itemid).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        else {
            alert("Success!")
            window.location.reload();
            return;
        }
    }
}



function DeleteProductItem(itemid) {
    if (confirm("Xóa sản phẩm sẽ xóa các đơn hàng liên quan,\n\n chắc chắn xóa?")) {
        RetValue = BLL.CmsBLL.Products_DeleteItem(itemid).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        else {
            alert("Xoá bản ghi thành công!")
            window.location.reload();
            return;
        }
    }
}


function DeleteCategoryItem(itemid) {
    if (confirm("Bạn muốn xóa bản ghi này?")) {
        RetValue = BLL.CmsBLL.Category_DeleteItemString(itemid).value;
        if (RetValue.indexOf("ERROR") != -1) {
            alert(RetValue);
            return;
        }
        else {
            alert("Xoá bản ghi thành công!")
            window.location.reload();
            return;
        }
    }
}



function DeleteImageFromList(imagename) {
    if (confirm("Bạn muốn xóa ảnh: " + imagename + " khỏi danh sách ảnh liên quan?")) {
        var strlistotherimage = new String(document.getElementById("strListOtherImage").value);
        RetValue = administrator_uc_admin_e_products.DeleteImageFromListImage(imagename, strlistotherimage).value;
        document.getElementById("divContentListImage").innerHTML = RetValue;
        //administrator_uc_admin_e_products.DeleteImageFromListImage(imagename, strlistotherimage);
        //document.getElementById("divContentListImage").innerHTML = RetValue;
      
    }
}
//get user selected value
function SetValue() {
    window.location.reload();
    //refresh();
    return;
}
function CloseWindows() {
    window.opener.SetValue();
    window.close();
}
function DoClose() {
    window.close();
}
//CheckAll Item in GridView
function SelectAllCheckBoxes(spanChk) {

    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
    var theBox = (spanChk.type == "checkbox") ?
        spanChk : spanChk.children.item[0];
    xState = theBox.checked;
    elm = theBox.form.elements;

    for (i = 0; i < elm.length; i++)
        if (elm[i].type == "checkbox" &&
              elm[i].id != theBox.id) {
            //elm[i].click();
            if (elm[i].checked != xState)
                elm[i].click();
            //elm[i].checked=xState;
        }
}
function GroupUserGetValue(drop) {
    var groupid = drop.options[drop.selectedIndex].value;
    var pageurl = "../administrator/default.aspx?mod=m_groupuser&groupid=" + groupid + "";
    document.location.href = pageurl;
} 
function LeftMenuGroupGetValue(drop) {
    var groupid = drop.options[drop.selectedIndex].value;
    var pageurl = "../administrator/default.aspx?mod=m_leftmenugroup&groupid=" + groupid + "";
    document.location.href = pageurl;
}
function GroupModuleGetValue(drop) {
    var groupid = drop.options[drop.selectedIndex].value;
    var pageurl = "../administrator/default.aspx?mod=m_groupmodule&groupid=" + groupid + "";
    document.location.href = pageurl;
}
